#include "widget.h"

#include <QApplication>
#include <QDebug>
#include "chineseletterhelper.h"

QString replaceChineseWithEnglish(const QString &str)
{
    QString result;

    for (int i = 0; i < str.length(); ++i) {
        QChar ch = str.at(i);

        if (ch >= QChar(0x4e00) && ch <= QChar(0x9fff)) {
            // If the character is Chinese, replace it with a space
            result.append(' ');
        } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
            // If the character is English, keep it as it is
            result.append(ch);
        } else {
            // For other characters, replace with a space (adjust this as needed)
            result.append(' ');
        }
    }

    return result;
}


int main(int argc, char *argv[])
{
    // QApplication a(argc, argv);
    // Widget w;
    // w.show();
    // return a.exec();

    QString testStr = "Hello 你好 Qt！这是一个测试文本。";
    QString convertedStr = replaceChineseWithEnglish(testStr);

    qDebug() << "Original String:" << testStr;
    qDebug() << "Converted String:" << convertedStr;


    QStringList tests;
    tests << "Hello * ，。！= ？ world 你好 世界"
          << "我是中国人"
          << "你好朋友";

    foreach (QString test, tests) {
        QString firstLetter = ChineseLetterHelper::GetFirstLetter(test);
        QString firstLetters = ChineseLetterHelper::GetFirstLetters(test);
        QString pinyin = ChineseLetterHelper::convertToEnglish(test);

        qDebug() << "src:         " << test;
        qDebug() << "firstLetter: " << firstLetter;
        qDebug() << "firstLetters:" << firstLetters;
        qDebug() << "pinyins:     " << pinyin;
        qDebug() << "-------------";
    }

    return 0;
}

#if 0

src:          "Hello world 你好 世界"
firstLetter:  "H"
firstLetters: "Hello world NH SJ"
pinyins:      "NIHAOSHIJIE"
-------------
src:          "我是中国人"
firstLetter:  "W"
firstLetters: "WSZGR"
pinyins:      "WOSHIZHONGGUOREN"
-------------
src:          "你好朋友"
firstLetter:  "N"
firstLetters: "NHPY"
pinyins:      "NIHAOPENGYOU"
-------------

#endif
